home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / snpd9611.zip / DATE__.C < prev    next >
C/C++ Source or Header  |  1996-11-24  |  5KB  |  112 lines

  1. /* +++Date last modified: 12-Nov-1996 */
  2.  
  3. /****************************************************************************
  4. *@(#) date_mac_conv() - Converting a date string with the format from
  5. *@(#)    macro __DATE__ to ISO standard.
  6. *
  7. ****************************************************************************
  8. *@(#)1992 Erik Bachmann  (E-mail: ebp@dde.dk)
  9. *
  10. * Released to public domain 27-Oct-95
  11. ****************************************************************************/
  12.  
  13. #include <stdio.h>                     /* scanf, sprintf */
  14. #include <string.h>                    /* strcpy, strcmp */
  15. #include "bacstd.h"                    /* _CfnTYPE */
  16.  
  17. /*
  18.  /-------------------------------------\
  19. |     DATE_MAC_CONV                     |------------------------------------|
  20. |\-------------------------------------/                                    
  21. | Converting a date string with the format from __DATE__ to ISO standard     
  22. |                                                                            
  23. |                                                                            
  24. |                                                                            
  25. | Example:   "Sep 16 1992" -> "1992-09-16"                                   
  26. |                                                                            
  27. |----------------------------------------------------------------------------|
  28. | CALL:                                                                      
  29. |    strcpy(string, date_mac_conv(string) ) ;                                 
  30. |                                                                            
  31. | HEADER:                                                                    
  32. |    stdio.h     : scanf, sprint                                             
  33. |    string.h    : strcpy, strcmp                                            
  34. |                                                                            
  35. | GLOBALE VARIABLES:                                                         
  36. |    %                                                                       
  37. |                                                                            
  38. | ARGUMENTS:                                                                 
  39. |    pszDate     : String containing __DATE__ format.                        
  40. |                                                                            
  41. | PROTOTYPE:                                                                 
  42. |    char _CfnTYPE *date_mac_conv(char *pszDate) ;                            
  43. |                                                                            
  44. | RETURN VALUE:                                                              
  45. |    char        : ISO date format YYYY-MM-DD (length 8 char)                
  46. |                                                                            
  47. | MODULE:                                                                    
  48. |    date__.c                                                                
  49. |----------------------------------------------------------------------------|
  50. |                                                                            
  51. |                                                                            
  52. |                                                                            
  53. |                                                                            
  54. |----------------------------------------------------------------------------|
  55. |1992-09-16/Erik Bachmann                                                   
  56. \---------------------------------------------------------------------------|*/
  57.  
  58. char _CfnTYPE *date_mac_conv(char *pszDate)
  59. {
  60.    char  *paMonth[12] = {"Jan", "Feb", "Mar", "Apr","May", "Jun", "Jul", "Aug",
  61.                         "Sep", "Oct", "Nov", "Dec"} ;
  62.                                        /* Names of months */
  63.  
  64.    char  szString[12] ;                /* String fore convertion */
  65.    char  cMonth[4],                    /* Month */
  66.          cDay[3],                      /* Day */
  67.          cYear[5] ;                    /* Year */
  68.    int   iCounter  ;                   /* Local counter */
  69.  
  70.    /*-----------------------------------------------------------*/
  71.    
  72.    strcpy(szString, pszDate) ;            /* Get string to convert */
  73.    
  74.    sscanf(szString, "%s %s %s", cMonth, cDay, cYear) ;
  75.                                        /* Split string */
  76.    
  77.    for ( iCounter = 11  ; iCounter >= 0 ; iCounter--)
  78.                                        /* loop for testing month */
  79.    {
  80.       if (strcmp(cMonth, paMonth[iCounter]) == 0)
  81.                                        /* - IF month is found */
  82.       {
  83.          sprintf(cMonth, "%0.2i", iCounter + 1 ) ;
  84.                                        /* - - Insert counter + 1 as month */
  85.          break ;
  86.       }
  87.    }
  88.  
  89.    /* Check valid day */
  90.    iCounter = atoi( cDay ) ;
  91.    if ( ( 1 > iCounter ) || ( 31 < iCounter ) )
  92.       strcpy( cDay, "01" ) ;
  93.  
  94.    sprintf(szString, "%04.4s-%02.2s-%02.2s", cYear,cMonth,cDay) ;
  95.                                        /* Merge ISO date */
  96.  
  97.    return( (char _CfnTYPE *) szString ) ;
  98. }  /*** date_mac_conv() ***/
  99.  
  100. #ifdef TEST
  101. main()
  102. {
  103.    char  szString[20] ;
  104.  
  105.    /*--------------------------------*/
  106.  
  107.    printf( "\n%s\n", date_mac_conv( __DATE__ ) ) ;
  108.  
  109.    return( 0 ) ;
  110. }
  111. #endif
  112.